#include "stdafx.h"
#include "SlowTower.h"
#include "SlowProjectile.h"
#include "EntityManager.h"
#include "EntityFactory.h"

SlowTower::SlowTower(const EEntityType& entity_type, EntityFactory* entity_factory, EntityManager* entity_manager, TargetMediator* target_mediator) 
	: BasicTower(entity_type, entity_factory, entity_manager, target_mediator)
{
}

SlowTower::~SlowTower(void)
{
}

void SlowTower::Init(SceneObject* scene_object, Grid* grid)
{
	BasicTower::Init(scene_object, grid);
}

void SlowTower::Update(float deltatime)
{
	BasicTower::Update(deltatime);
}

void SlowTower::Shoot(Entity* target)
{
	Vector3 target_position = target->GetPosition();
	Vector3 direction = target_position - m_position;
	direction.Normalize();

	Entity* projectile = m_entity_factory->Create(Slow_Projectile, m_grid);
	m_entity_manager->AddEntity(projectile);
	projectile->SetPosition(m_position);

	if (projectile->GetEntityType() == Slow_Projectile){
		Projectile* p = static_cast<Projectile*>(projectile);
		p->SetPosition(m_position);
		p->SetDirection(direction);
	}
	projectile->Update(0.0f);
}